package com.film.admincontroller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.film.domain.Admin;
import com.film.domain.Director;
import com.film.domain.Film;
import com.film.domain.Performer;
import com.film.domain.Review;
import com.film.domain.User;
import com.film.service.AdminService;
import com.film.service.DirectorService;
import com.film.service.FilmService;
import com.film.service.PerformerService;
import com.film.service.ReviewService;
import com.film.service.ShowingsService;
import com.film.service.UserService;
import com.film.service.impl.AdminServiceImpl;
import com.film.service.impl.DirectorServiceImpl;
import com.film.service.impl.FilmServiceImpl;
import com.film.service.impl.PerformerServiceImpl;
import com.film.service.impl.ReviewServiceImpl;
import com.film.service.impl.ShowingsServiceImpl;
import com.film.service.impl.UserServiceImpl;



@WebServlet("/AdminController")
public class AdminController extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		AdminService as=new AdminServiceImpl();
		UserService us=new UserServiceImpl();
		FilmService fs=new FilmServiceImpl();
		DirectorService ds=new DirectorServiceImpl();
		PerformerService pf=new PerformerServiceImpl();
		ReviewService rs=new ReviewServiceImpl();
		ShowingsService ss =new  ShowingsServiceImpl();
		
		
		
		
		
		String username= request.getParameter("username");
		String password= request.getParameter("password");
		
		if(as.login(username, password)!=null) {
			Admin ad=new Admin(username,password);
			HttpSession session = request.getSession();
			List<User> listuser=us.selectALl();
			List<Film> listfilm=fs.selectAllFilm();
			List<Director> listdirector=ds.selectAllDirector();
			List<Performer> listperformer=pf.selectAllPerformer();
			List<Review> listReview=rs.selectReview();
			List<String> listshowins=ss.selectShowingsAll();
			
			
			
			
			
			session.setAttribute("admin", ad);
			session.setAttribute("listuser", listuser.size());
			session.setAttribute("listfilm", listfilm.size());
			session.setAttribute("listdirector", listdirector.size());
			session.setAttribute("listperformer", listperformer.size());
			session.setAttribute("listReview", listReview.size());
			session.setAttribute("listshowins", listshowins.size());
			
			
			
			
			
			
			response.sendRedirect("admin_jsp/main.jsp?flag=1");
		}else {
			response.sendRedirect("admin_jsp/index.jsp?flag=1");
		}
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
